package com.guslegend.spzx.manager.controller;

import com.github.pagehelper.PageInfo;
import com.guslegend.spzx.manager.service.SysUserService;
import com.guslegend.spzx.model.dto.system.SysUserDto;
import com.guslegend.spzx.model.entity.system.SysRole;
import com.guslegend.spzx.model.entity.system.SysUser;
import com.guslegend.spzx.model.entity.user.UserInfo;
import com.guslegend.spzx.model.vo.common.Result;
import com.guslegend.spzx.model.vo.common.ResultCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: guslegend
 * @description: 用户管理控制层
 * @create: 2025-05-08 07:50
 **/
@RestController
@RequestMapping(value = "/admin/system/sysUser")
public class SysUserControlller {

    @Autowired
    private SysUserService sysUserService;

    @GetMapping(value = "/findByPage/{pageNum}/{pageSize}")
    public Result<PageInfo<SysRole>> findByPage(SysUserDto sysUserDto,
                                                @PathVariable(value = "pageNum") Integer pageNum,
                                                @PathVariable(value = "pageSize") Integer pageSize){
        PageInfo<UserInfo> pageInfo=sysUserService.findByPage(sysUserDto,pageNum,pageSize);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }

    @PostMapping(value = "/saveSysUser")
    public Result saveSysUsser(@RequestBody SysUser sysUser){
        sysUserService.saveSysUser(sysUser);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @PutMapping(value = "/updateSysUser")
    public Result updateSysUser(@RequestBody SysUser sysUser) {
        sysUserService.updateSysUser(sysUser) ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }

    @DeleteMapping(value = "/deleteById/{userId}")
    public Result deleteById(@PathVariable(value = "userId") Long userId) {
        sysUserService.deleteById(userId) ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }
}
